// pages/userCenter/userCenter.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList:[], // 活动者发布过的活动数据列表
    userInfo:{}, //用户个人信息
    type:"",
    reasonList:[]
  },

  onLoad(options) {
    // 可以拿到详情页面中传递过来的用户openid
    const that = this;
    const openid = options.openid;
    this.getDataList(openid);
    this.getUserInfo(openid);
    this.setData({
      type:options.type
    })
    // 当为举报类型的才显示
    if(options.type === "report"){
      // 加载数据
      wx.cloud.callFunction({
        name:"downReportReasons",
        data:{
          type:1,
          activeId:'',
          openid:options.openid
        },
        success:res=>{
          console.log("下载举报理由成功",res.result.data[0]);
          that.setData({
            reasonList:res.result.data[0].reasonList
          })
        }
      })
    }
  },
  // 请求发不过去的活动数据类列表
  getDataList(openid){
    const that = this;
    wx.cloud.callFunction({
      name:"downUserPublish",
      data:{
        openid:openid
      },
      success:res=>{
        console.log("请求成功",res)
        that.setData({
          dataList:res.result.data
        })
      }
    })


  },

  // 获取活动发布者的个人信息
  getUserInfo(openid){
    const that = this;
    wx.cloud.callFunction({
      name:"downUserInfo",
      data:{
        openid:openid
      },
      success:res=>{
        console.log("个人信息",res)
        that.setData({
          userInfo:res.result.data[0]
        })
      }
    })
  },

  // 跳转到详情页面
  gotoDetail(e){
    // console.log('跳转到活动详情页',e);
    const item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: `/pages/detail/detail?id=${item._id}`
    });
  },

  // 跳转到举报中心页面
  toReport(){
    wx.navigateTo({
      url:`/pages/report/report?type=1&&openid=${this.data.userInfo.openid}`
    })
  },

  darkList(){
    let {userInfo} = this.data;

    // 用户加入黑名单
    wx.cloud.callFunction({
      name:"deleteUser",
      data:{
        openid:userInfo
      },
      success:res=>{
        console.log("加入黑名单，修改状态",res);
      }
    })

    wx.cloud.callFunction({
      name:"upDateReasonType",
      data:{
        id:"",
        openid:userInfo.openid
      },
      success:res=>{
        console.log("举报里面不在加载",res);
        wx.navigateTo({
          url: '/pages/admin/admin',
        });
      },
      fail:e=>{
        console.log("失败",e)
      }
    })
  }
})